﻿@implements IDisposable
@inject GlobalConfig GlobalConfig;

<MOverlay ZIndex=9999999 Value="IsLoading">
    <div class="d-flex flex-column">
        <MProgressCircular Indeterminate Size="64" Class="align-self-center"></MProgressCircular>
        <div class="mt-1">@LoadingText</div>
    </div>
</MOverlay>

@code {
    [Parameter]
    public bool IsLoading { get; set; }

    [Parameter]
    public string LoadingText { get; set; } = string.Empty;

    [Parameter]
    public EventCallback<bool> LoadingChanged { get; set; }

    void Loading(bool loading,string loadingText)
    {
        IsLoading = loading;
        LoadingText = loadingText;
        base.StateHasChanged();
    }

    protected override void OnInitialized()
    {
        GlobalConfig.OnLoadingChanged += Loading;
    }

    public void Dispose()
    {
        GlobalConfig.OnLoadingChanged -= Loading;
    }
}